// File Name: key_interface.h
// Author: kukukukuku~
// Date: 2024-12-24

#ifndef __KEY_INTERFACE_H
#define __KEY_INTERFACE_H

#include "./Key/inc/key_ctrl.h"
#include "./Key/inc/key_init.h"

//Key状态
typedef enum KEY_STATE_T
{
    KEY_STATE_RELEASE,      //松开
    KEY_STATE_PRESS,        //按下
}KEY_STATE_T;

//Key处理
typedef enum KEY_HANDLE_T
{
    KEY_HANDLE_NONE,    //不处理
    KEY_HANDLE_CLICK,   //单击处理
    KEY_HANDLE_LONG,    //长按处理
}KEY_HANDLE_T;

//Key对象
typedef struct KEY_OBJECT_T
{
    KEY_GPIO_OBJECT_T *gpio;
    uint16_t pressCount;
    uint16_t longPressJudgeNum;
    uint16_t longPressJudgeCnt;
    uint8_t pressFlag;
    uint8_t longPressScanFlag;
    uint8_t pressPolarity;
    KEY_STATE_T state;
    KEY_HANDLE_T handle;
}KEY_OBJECT_T, *pKEY_OBJECT_T;


void key_object_init(KEY_OBJECT_T * const keyObj, const KEY_GPIO_OBJECT_T * const gpio, const uint16_t longPressJudgeNum, const uint8_t pressPolarity);

void key_int_long_press_scan_callback(KEY_OBJECT_T * const keyObj);

void key_scan(KEY_OBJECT_T * const keyObj);

uint8_t key_is_long_press_triged(KEY_OBJECT_T * const keyObj);
uint8_t key_is_click_triged(KEY_OBJECT_T * const keyObj);
void key_clear_click_handle(KEY_OBJECT_T * const keyObj);

uint8_t key_long_press_scan_flag_get(KEY_OBJECT_T * const keyObj);

#endif //__KEY_INTERFACE_H
